Ubuntu 14.04
Sponsored Link

Docker : Access to Containers
2014/06/16
 
If you'd like to access to services like HTTP or SSH which is running in Containers as a daemon, set like follows.
[1] For exmaple, use a Container which has sshd.
# start the Container and connect to the shell session

# map the port of Host and the port of Container with "-p xxx:xxx"

root@dlp:~#
docker run -it -p 8081:22 my_image/ubuntu_sshd /bin/bash
# start sshd & create a user for connecting with SSH and exit the Container

root@dae3e99c727d:/#
/etc/init.d/ssh start

* Starting OpenBSD Secure Shell server sshd [ OK ]
root@dae3e99c727d:/#
adduser ubuntu

root@dae3e99c727d:/#
# exit with Ctrl+p, Ctrl+q
root@dlp:~#
docker ps

CONTAINER ID  IMAGE                         COMMAND    CREATED         STATUS          PORTS                  
dae3e99c727d  my_image/ubuntu_sshd:latest   /bin/bash  53 seconds ago  Up 53 seconds   0.0.0.0:8081->22/tcp

# connect to the port configured with SSH

root@dlp:~#
ssh ubuntu@localhost -p 8081

The authenticity of host '[localhost]:8081 ([::1]:8081)' can't be established.
ECDSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:c1:a6:e5.
Are you sure you want to continue connecting (yes/no)?
yes

Warning: Permanently added '[localhost]:8081' (ECDSA) to the list of known hosts.
ubuntu@localhost's password:
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.2.0-58-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

ubuntu@dae3e99c727d:~$
# just logined to the Container
 
Tweet